package com.iwdnb.gkgz.controller;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.Executor;

import cn.hutool.core.date.DateUtil;
import com.google.common.collect.Lists;
import com.iwdnb.bmnf.common.model.result.Result;
import com.iwdnb.bmnf.common.service.CacheService;
import com.iwdnb.gkgz.application.model.vo.StockType;
import com.iwdnb.gkgz.application.service.HistoryDataService;
import com.iwdnb.gkgz.application.service.RealtimeStockService;
import com.iwdnb.gkgz.application.service.StockDayDataSerivce;
import com.iwdnb.gkgz.application.service.StockFenshiService;
import com.iwdnb.gkgz.application.service.StockService;
import com.iwdnb.gkgz.application.service.impl.StockFenshiServiceImpl.FenshiStatistics;
import com.iwdnb.gkgz.common.model.dto.StockDayData;
import com.iwdnb.gkgz.common.utils.WorkDayUtils;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * 股票分时数据处理
 *
 * @author wbc
 * @date 2024/12/10
 **/
@RestController
@RequestMapping("/api/stock/fenshi")
@Slf4j
public class StockFenshiController {

    @Autowired
    private Executor executor;

    @Autowired
    private StockFenshiService stockFenshiService;

    /**
     * 计算指定日期的股票卖出信息
     *
     * @param date
     * @return
     */
    @RequestMapping("/calculateSellInfo")
    public Result<Map<String, Map<String, FenshiStatistics>>> calculateSellInfo(String begin, String end,
        String codes) {
        List<Date> dateList = WorkDayUtils.getWorkDayList(DateUtil.parseDate(begin), DateUtil.parseDate(end));
        Map<String, Map<String, FenshiStatistics>> map = new HashMap<>();
        for (Date date : dateList) {
            String dateStr = DateUtil.formatDate(date);
            Map<String, FenshiStatistics> statisticsMap = stockFenshiService.calculateSellInfo(
                dateStr, codes);
            map.put(dateStr, statisticsMap);
        }
        return Result.getSuccessResult(map);
    }

    /**
     * 修复分时数据的前一日收盘价
     *
     * @return
     */
    @RequestMapping("/fixFenshiBeforeClosePrice")
    public Result<String> fixFenshiBeforeClosePrice(String beginDate, String endDate) {
        stockFenshiService.fixFenshiBeforeClosePrice(beginDate, endDate);
        return Result.getSuccessResult(null);
    }

}
